# This software is Copyright (c) 2016 Denis Burykin
# [denis_burykin yahoo com], [denis-burykin2014 yandex ru]
# and it is hereby released to the general public under the following terms:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted.

CC = gcc
CFLAGS = -c -Wall -O2
CFLAGS_TEST = -O
#LD = ld
EXTRA_LIBS = -lusb-1.0

SUBDIRS = pkt_comm

TEST_OBJS = device.o inouttraffic.o ztex.o ztex_scan.o

OBJS = $(TEST_OBJS) device_format.o jtr_device.o jtr_mask.o task.o

TEST_EXTRA_OBJS = pkt_comm/pkt_comm.o pkt_comm/word_gen.o pkt_comm/word_list.o

EXTRA_OBJS = pkt_comm/*.o

#TESTS = simple_test test pkt_test


default: $(SUBDIRS) $(OBJS)
all: $(SUBDIRS) $(OBJS)

.PHONY: subdirs $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $@ all
	
device.o: device.c device.h
	$(CC) $(CFLAGS) device.c

inouttraffic.o: inouttraffic.c inouttraffic.h
	$(CC) $(CFLAGS) inouttraffic.c
	
ztex.o: ztex.c ztex.h
	$(CC) $(CFLAGS) ztex.c

ztex_scan.o: ztex_scan.c ztex_scan.h
	$(CC) $(CFLAGS) ztex_scan.c

device_format.o: device_format.c device_format.h
	$(CC) $(CFLAGS) device_format.c

jtr_device.o: jtr_device.c jtr_device.h
	$(CC) $(CFLAGS) jtr_device.c

jtr_mask.o: jtr_mask.c jtr_mask.h
	$(CC) $(CFLAGS) jtr_mask.c
	
task.o: task.c task.h
	$(CC) $(CFLAGS) task.c



simple_test: simple_test.c $(SUBDIRS) $(TEST_OBJS)
	$(CC) $(CFLAGS_TEST) simple_test.c $(TEST_OBJS) $(TEST_EXTRA_OBJS) $(EXTRA_LIBS) -o simple_test
	
test: test.c $(SUBDIRS) $(TEST_OBJS)
	$(CC) $(CFLAGS_TEST) test.c $(TEST_OBJS) $(TEST_EXTRA_OBJS) $(EXTRA_LIBS) -o test

pkt_test: pkt_test.c $(SUBDIRS) $(TEST_OBJS)
	$(CC) $(CFLAGS_TEST) pkt_test.c $(TEST_OBJS) $(TEST_EXTRA_OBJS) $(EXTRA_LIBS) -o pkt_test


clean:
	find . -name \*.o -exec rm -f "{}" \;
	rm -f *.exe simple_test test pkt_test
